<%@page import="com.sinba.common.system.dto.RuleDTO"%>
<%@page import="com.sinba.common.system.service.IRuleService"%>
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.sinba.common.system.dto.ExtractDTO"%>
<%@page import="com.sinba.common.system.dto.TransactionRecordDTO"%>
<%@page import="com.sinba.common.system.service.ITransactionRecordService"%>
<%@page import="com.sinba.common.system.service.IExtractService"%>
<%@page import="com.sinba.common.user.dto.AccountDTO"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.sinba.common.user.entity.Account"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="com.sinba.common.user.service.IAccountService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%
	if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/cashBusiness.jsp");
	return;
	}
	ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	
	ExtractDTO qdto = new ExtractDTO(); 
	qdto.setLoginName((String)session.getAttribute("loginName"));
	qdto.setParentAccount((String)session.getAttribute("loginName"));
	IExtractService extractService = (IExtractService)ac.getBean("extractService");
	int pages = 1;
	if(request.getParameter("pages")!=null && request.getParameter("_pages")!=""){
		pages = Integer.parseInt(request.getParameter("pages"));
	}
	int rows = 10;
	int start = ( pages - 1 ) * rows;
	PageDTO pageDTO = extractService.findPager(qdto,start,rows,"desc","createTime");
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
	request.setAttribute("pageDTO",pageDTO);
	
	
	//可提现余额
	ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
	Double txbalance1 = transactionRecordService.findUserBalance(session.getAttribute("loginName").toString(),"Dynamic");
	
	request.setAttribute("txbalance1",txbalance1);
	
	
	IRuleService ruleService = (IRuleService)ac.getBean("ruleService");
	RuleDTO ruleDTO = ruleService.findRuleInfo();
	request.setAttribute("ruleDTO",ruleDTO);
	
%>
<fmt:setLocale value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
	<fmt:setBundle basename="i18n.itilbase"/>
	<c:set var="lang" value="${empty cookie['language'].value?'zh_CN':cookie['language'].value}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta charset="UTF-8">
<title><fmt:message key="i18n.txYeWu"/>-<fmt:message key="i18n.title"/></title>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1" />


<!-- Bootstrap framework -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" />
<!-- breadcrumbs-->
	<link rel="stylesheet" href="lib/jBreadcrumbs/css/BreadCrumb.css" />
<!-- main styles -->
    <link rel="stylesheet" href="css/sub_page_main_style.css" />

<!--[if lte IE 8]>
    <link rel="stylesheet" href="css/ie.css" />
    <script src="js/ie/html5.js"></script>
    <script src="js/ie/respond.min.js"></script>
<![endif]-->

</head>
<body style="height:800px">

<!-- 主体内容 -->
<div id="contentwrapper">
	<div class="main_content">
		 <nav>
            <div id="jCrumbs" class="breadCrumb module">
                <ul>
                    <li>
                        <a href="main.jsp"><i class="icon-home"></i></a>
                    </li>
                    <li>
                        <a href="#"><fmt:message key="i18n.moneyManage"/></a>
                    </li>
                    <li>
                        <a href="#"><fmt:message key="i18n.acountTx"/></a>
                    </li>
                </ul>
            </div>
         </nav>
         
         <h3 class="heading"><fmt:message key="i18n.acountTx"/></h3>
         
	<div class="listCont">
    	<div class="listTable lttno">
    		<form id="cashBusinessForm" action="registerUser!userOpt.action" method="post" onsubmit="return checkform();" >
    			<input type="hidden" name="optType" value="TingXiangApply" />
				<input type="hidden" name="extractDTO.loginName" value="${session.loginName }" />
				<input type="hidden" name="pageUrl" value="cashBusiness.jsp" />
				<input type="hidden" value="${txbalance1 }" id="cashbussiness_balance1" />
				<input type="hidden" value="${txbalance2 }" id="cashbussiness_balance2" />
	        	<table width="100%" class="mytable" id="cashtable" >
	        		<tr>
	        			<td colspan="4" align="center" style="color:red;"><fmt:message key="i18n.zhuyi"/>：
						${ruleDTO.rule010 }</td>
	        		</tr>
	        		<tr>
	        			<td align="right" width="20%"><fmt:message key="i18n.dyBalance"/>：</td>
	        			<td align="left" width="20%">${txbalance1}</td>
	        			<!-- <td>&nbsp;</td> -->
	        			<td colspan="2" >
	        				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key="i18n.secretSecurityTip"/>
	        			</td>
	        		</tr>
	        		<tr>
	        			<td align="right"><fmt:message key="i18n.txAccount"/>：</td>
	        			<td align="left">
							<select id="dtype" name="extractDTO.dtype">
								<option value="Dynamic"><fmt:message key="i18n.dyAccount"/></option>
							</select>
						</td>
	        			<td align="right" width="10%"><fmt:message key="i18n.ptype"/>：</td>
	        			<td align="left" width="50%">
							<select class="regSele" name="extractDTO.passwordProblem" >
                            	<jsp:include page="PwdProblem.jsp"></jsp:include>
							</select>
						</td>
	        		</tr>
	        		<%-- <tr>
						<td align="right" width="50%"><fmt:message key="title.daozhangTime"/>:</td>
						<td align="left">
							<select name="daoZhangTimeItem">
								<option value="DaozhangTimeItem1"><fmt:message key="title.daozhangTimeItem1"/></option>
								<option value="DaozhangTimeItem2"><fmt:message key="title.daozhangTimeItem2"/></option>
							</select>
						</td>
					</tr> --%>
	        		<tr>
	        			<td align="right"><fmt:message key="i18n.txMoney"/>：</td>
	        			<td align="left">
	        			<input name="extractDTO.tixiangSum" id="extractMoney" class="easyui-numberbox" validType="number" />
	        			<span style="color: red; display: none;"><fmt:message key="i18n.toRmb"/>(RMB):</span>
	        			<span id="changeRmb" style="color: red;">*</span>
	        			</td>
	        			<td align="right"><fmt:message key="i18n.answer"/>：</td>
	        			<td align="left">
	        				<input name="extractDTO.passwordAnswer" id="passwordAnswer" class="easyui-numberbox" />
	        				<span style="color: red;">&nbsp;&nbsp;*</span>
	        			</td>
	        		</tr>
	        		<!--  
	        		<tr>
						<td align="right">开户银行:</td>
						<td align="left">
							<select name="extractDTO.accountType">
								<option value="财付通">财付通</option>
								<option value="工商银行">工商银行</option>
								<option value="农行银行">农行银行</option>
								<option value="建设银行">建设银行</option>
							</select>
						</td>
					</tr>
					<tr>
						<td align="right">银行卡号:</td>
						<td align="left"><input name="extractDTO.bankAccount" class="easyui-validatebox"  /></td>
					</tr>
					<tr>
						<td align="right">开户名:</td>
						<td align="left"><input name="extractDTO.accountName" class="easyui-validatebox"  /></td>
					</tr>
					<tr>
						<td align="right">开户地址:</td>
						<td align="left"><input name="extractDTO.openBankAddress" class="easyui-validatebox"  /></td>
					</tr>-->
	        		<%-- <tr>
	        			<td align="right"><fmt:message key="i18n.valicode"/>:</td>
	        			<td align="left">
	        			<input class="easyui-validatebox" id="cashBusiness_validCode" />
	        			<input type="hidden" value="${session.loginName }" id="cashBusiness_loginName" />
		        			<input type="button" value="<fmt:message key="i18n.getEmailValiCode"/>" id="cashBusiness_loginName_button" onclick="getEmailActivationCode('邮件','提现','#cashBusiness_loginName')"> 
   						<span id="cashBusiness_loginName_show"></span>
	        			</td>
	        		</tr> --%>
	        		<tr>
	        			<td colspan="2">&nbsp;</td>
	        			<td align="center">
	        			<c:if test="${not empty session.activationTime}">
	        			<input type="submit" value="<fmt:message key="i18n.txApply"/>" />
	        			</c:if></td>
	        			<td>&nbsp;</td>
	        		</tr>
	        	</table>
			</form>
    	
    		
    		<!-- 提现记录 -->
		        <div style="padding: 5px;" align="left" >
		        	<form id="cashBusiness_form">
		        	<table width="100%" id="tr_cashBusiness_table" class="table table-bordered table-striped">
	        			<tr>
	        				<th><fmt:message key="i18n.userbianhao"/></th>
	        				<th><fmt:message key="i18n.txMoney"/></th>
	        				<th><fmt:message key="i18n.applyDate"/></th>
	        				<th><fmt:message key="i18n.acceptDate"/></th>
	        				<th><fmt:message key="i18n.acceptStatus"/></th>
	        				<!-- 
	        				<th>开户银行</th>
	        				<th>银行卡号</th>
	        				<th>开户名</th>
	        				<th>开户地址</th> -->
	        				<th><fmt:message key="i18n.remark"/></th>
	        			</tr>
		        		<c:if test="${pageDTO.totalSize eq 0}">
						<tr><td colspan="10" align="center"><fmt:message key="i18n.noData"/>!</td></tr>
						</c:if>	
						<c:if test="${pageDTO.totalSize ne 0}">
							<c:forEach items="${pageDTO.data}" var="data">
							<tr>
								<td>${data.loginName }</td>
								<td>${data.tixiangSum }</td>
								
								<td><fmt:formatDate value="${data.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
								<td><fmt:formatDate value="${data.handTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
								<td>${data.status}</td>
								<!--  
								<td>${data.accountType}</td>
								<td>${data.bankAccount}</td>
								<td>${data.accountName}</td>
								<td>${data.openBankAddress}</td>-->
								<td>
								${data.formAccountStr}(${data.remark})
								</td>
							</tr>
							</c:forEach>
						</c:if>       		
		        	</table>
		        	</form>
		        	
		        	<!-- 分页 start -->
					<div class="page">
					<div id="tr_recommendGrid_pager" class="page_r">
						<ul>
							<li><a href="cashBusiness.jsp?pages=1"><fmt:message key="i18n.firstPage"/></a></li>
							<c:if test="${pageDTO.page!=1}">
								<li><a href="cashBusiness.jsp?pages=${pageDTO.page-1}"><fmt:message key="i18n.upPage"/></a></li>
							</c:if>
							<li><a>${pageDTO.page}/${pageDTO.total}</a></li>
							<c:if test="${pageDTO.page+1<=pageDTO.total}">
								<li><a href="cashBusiness.jsp?pages=${pageDTO.page+1}"><fmt:message key="i18n.nextPage"/></a></li>
							</c:if>
							<li><a href="cashBusiness.jsp?pages=${pageDTO.total}"><fmt:message key="i18n.endPage"/></a></li>
							<li><a><fmt:message key="i18n.total"/>${pageDTO.totalSize}<fmt:message key="i18n.tiao"/></a></li>
						</ul>
					</div>
					</div>
					<!-- 分页 end  -->
		        	
				<!-- end 提现记录 -->
    		
    		
    	</div>
    </div>	
</div>
				
</div>
</div>

<script type="text/javascript" src="../scripts/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../scripts/user/common.js"></script>
<script>
$(function(){
	var _result = '${param.result}';
	if(_result=='TixiangSumGeBalance'){
		alert('The withdrawal amount is greater than can(提现金额大于可提现金额)!');
		window.location.href="cashBusiness.jsp";
	}else if(_result=='ApplyLoginNameNotExist'){
		alert('Apply for membership does not exist(申请的会员不存在)!');
		window.location.href="cashBusiness.jsp";
	}else if(_result=='Success'){
		alert('Successful applicants will be accepted as soon as possible, the financial(申请成功，财务会尽快受理)!');
		window.location.href="cashBusiness.jsp";
	}
})

function changeRmb(){
	//$('#changeRmb').text($('#extractMoney').val()*4);
}


function checkform(){
	//alert('此期间与英国本部进行财务对接，不允许提现，详情请查看公告!');
	//return false;
	/* if($('#cashBusiness_validCode').val()==null || $('#cashBusiness_validCode').val()==''){
		alert('Please input the valid code(请输入验证码)!');
		return false;
	}
	 */
	var extractMoney = $('#extractMoney').val();
	if(extractMoney==null || extractMoney==''){
		alert('Please input the withdrawal(请输入提现金额)!');
		return false;
	}
	if(extractMoney % 10 != 0){
		alert('Please enter 10 times the amount(请输入10的倍数提现金额)!');
		return false;
	}
	if(extractMoney < 10){
		alert('Minimum withdrawals over 100(最低提现100以上)!');
		return false;
	}
	
	if($('#passwordAnswer').val()==''){
		alert('Secret security answer can not be empty(密保答案不能为空)!');
		$('#passwordAnswer').focus();
		return false;
	}
	if($('#dtype').val()=='Dynamic' &&  parseFloat($('#cashbussiness_balance1').val())<parseFloat($('#extractMoney').val())){
		 alert('Extraction of failure, can be extracted in excess of the amount(提取失败,可提取金额超出)!');
		 return false;
	}
	if($('#dtype').val()=='Static' &&  parseFloat($('#cashbussiness_balance2').val())<parseFloat($('#extractMoney').val())){
		 alert('Extraction of failure, can be extracted in excess of the amount(提取失败,可提取金额超出)!');
		 return false;
	}
	
	
	/* $.post('activationCode!authEmailCode.action','dto.type=邮件&dto.category=提现&dto.activationCode='+$('#cashBusiness_validCode').val(),function(res){
		 if(!res){
			 alert('E-mail verification code is not correct(邮箱验证码不正确)!');
			 return false;
		 }else{
			 $('#cashBusinessForm').submit();
		 }
	}); */
}

</script>


</body>
</html>